//
//  UIButton+Extension.swift
//  SwiftSina
//
//  Created by 刘战军 on 16/5/15.
//  Copyright © 2016年 LiuZhanJun. All rights reserved.
//

import UIKit

extension UIButton {
    /**
    创建按钮
    
    - parameter title:         按钮中文字
    - parameter color:         按钮中文字的颜色默认是 darkGrayColor()
    - parameter imageName:     按钮中的图片默认是 nil
    - parameter backImageName: 按钮中的背景图片默认是 nil
    
    - returns: UIButton
    */
    convenience init(title: String?,color: UIColor = UIColor.darkGrayColor(),imageName: String? = nil, backImageName: String? = nil) {
     self.init()
        
        self.setTitle(title, forState: .Normal)
        self.setTitleColor(color, forState: .Normal)
        
        if let imageName = imageName {
            self.setImage(UIImage(named: imageName), forState: .Normal)
            self.setImage(UIImage(named: imageName + "_highlighted"), forState: .Highlighted)
        }
        
        if let backImageName = backImageName {
            self.setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
            self.setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: .Highlighted)
        }
    }
    
    
}
